<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/notes.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Kevin's Homepage</title>
<!-- InstanceEndEditable -->
<link href="../main.css" rel="Stylesheet">



<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<body>

<div id="container">

		<div id="imagehi"><img id="hi" src="../images/hi.gif" alt="picture hi" /></div>
	
  		<div id="rightcolumn">
		<div id="title">
			<h1 id="titletext">Kevin's Home</h1>
		</div>
		
		<ol id="navlinks">
			<li><a href="../index.html">Home</a></li>
			<li><a href="../aboutmyself.html">About Myself</a></li>
			<li><a href="../photoalbum/photoalbum.html">Photo Album</a></li>
			<li><a href="notes.html">Quick Notes</a></li>
			<li class="last"><a href="../links.html">Links</a></li>
		</ol>
		
	    
	<div id="leftbar">  
		<ol>
			<li><a href="c.html">C &amp; C++</a></li>
			<li><a href="java.html">Java</a></li>
			<li><a href="perl.html">Perl</a></li>
			<li><a href="centos.html">Centos</a></li>
			<li><a href="unix.html">Unix</a></li>
			<li><a href="css.html">CSS</a></li>
			<li><a href="php.html">PHP</a></li>
			<li><a href="sql.html">SQL</a></li>
			<li><a href="photoshop.html">Photoshop</a></li>
			<li><a href="windows.html">Windows</a></li>
			<li><a href="numbers.html">Numbers</a></li>
			<li><a href="misc.html">Misc</a></li>
		</ol>
	</div><!-- end of leftbar -->
	    <!-- InstanceBeginEditable name="EditRegion_submain" -->
	    <div id="main">
  <h3>Linux</h3>
  
	<h4>Basic commands</h4>
    <div class="codeblock">lynx http://httpd.apache.org/dist/httpd/apache_1.3.24.tar.gz<br>
	  wget http://httpd.apache.org/dist/httpd/apache_1.3.24.tar.gz<br>
	  gzip -d -c apache_1.3.24.tar.gz | tar xvf -<br>
	  tar xvzf file.tar.gz or gunzip file.tar.gz | tar xvf<br>
	  ftp hostname portnumber<br>
	  or in internet browser ftp://userid@hotname:portnumber<br />ls -F --color=auto</div><br />
	  <br>

<table class="utable">
<tbody>
	<tr>
	    <td>man -k keyword</td>
	 	<td>search for keyword in man page</td>
	</tr>
	<tr>
	    <td>man iptables | cel -b > /tmp/iptables.man</td>
	    <td></td>
	</tr>
	<tr>
	    <td>chsh</td>
	    <td>change default login shell</td>
	</tr>
	<tr>
	    <td>tar tvf file.tar</td>
	    <td>list table of content</td>
	</tr>
 	<tr>
	    <td>tar xvzf file.tar.gz</td>
	    <td>unzip and untar file.tar.gz</td>
	</tr>
	<tr>
	    <td>tar cvf name.tar files</td>
	    <td>create tar files</td>
	</tr>
	<tr>
	    <td>/path/to/script | tee log.txt</td>
	    <td>output to screen and write to file</td>
	</tr>
	<tr>
	    <td>clear</td>
	    <td>clear console window</td>
	</tr>
	<tr>
	  <td>chmod 400 myfile</td>
	  <td>Gives the user read permission, and removes all other permission. These permissions are specified in octal, the first char is for the user, second for the group and the third is for other. The high bit (4) is for read access, the middle bit (0) os for write access, and the low bit (1) is for execute access.</td>
	  </tr>
	<tr>
	  <td>chmod u+x myfile<br />
	    chmod +x myfile<br />
	    chmod ugo+x myfile<br />
	    chmod 764 myfile<br />
	    chmod 751 myfile<br />
	    chmod +s myfile<br />
	    chmod go-rx myfile</td>
	  <td>Gives the user execute permission on myfile.<br />
	    Gives everyone execute permission on myfile.<br />
	    Same as the above command, but specifically specifies user, group and other.<br />
	    Gives user full access, group read and write access, and other read access.<br />
	    Gives user full access, group read and execute permission, and other, execute permission.<br />
	    Set the setuid bit.<br />
	    Remove read and execute permissions for the group and other.</td>
	  </tr>
	<tr>
	    <td><br />
        </td>
	    <td></td>
	</tr>
	<tr>
	  <td>ln -s /path/to/file1 file2</td>
	  <td>create a symbolic (soft) link to file1 with the name file2</td>
	  </tr>
	<tr>
	  <td>alias<br />
	    alias ls='ls -F --color=tty'</td>
	  <td>list existing alias <br />
	    set alias for ls</td>
	  </tr>
	<tr>
	    <td>PATH=$PATH:$HOME/bin<br />
			VARIABLE=VALUE <br />
			export PATH VARIABLE</td>
		<td>export PATH and variable to environment for Bourne, Korn and Bash</td>
	</tr>
	<tr>
	    <td>setenv TERM vt100</td>
	    <td>C shell set env variable</td>
	</tr>
	<tr>
	    <td>printenv VARIABLE</td>
	    <td>display environment variable</td>
	</tr>
	<tr>
	    <td>echo $VARIABLE</td>
	    <td></td>
	</tr>
	<tr>
	    <td>env | grep VARIABLE</td>
	    <td>env will display all environment variables</td>
	</tr>
	<tr>
	    <td>stty -a</td>
	    <td>show all terminal setting</td>
	</tr>
	<tr>
	    <td>0</td>
	    <td>standard input (generally keyboard)</td>
	</tr>
	<tr>
	    <td>1</td>
	    <td>standard output (generally display/screen)</td>
	</tr>
	<tr>
	    <td>2</td>
	    <td>standard err output (generally display screen)</td>
	</tr>
	<tr>
	    <td>ls > listing.txt</td>
	    <td></td>
	</tr>
	<tr>
	    <td>mail a7063c@motorola.com < letter</td>
	    <td></td>
	</tr>
	<tr>
	    <td>my_script 2 >> err_log.txt</td>
	    <td></td>
	</tr>
	<tr>
	    <td>/dev/null</td>
	    <td>is a black hole in unix</td>
	</tr>
	<tr>
	    <td>find / -name file 2 > /dev/null</td>
	    <td>whatever sent to /dev/null never return</td>
	</tr>
	<tr>
	    <td>sort < /etc/passwd > foo 2 > err</td>
	    <td>sort the /etc/passwd file, place the result in foo, and put any errors in err</td>
	</tr>
	<tr>
	    <td>script >> log.txt 2 > &1 </td>
	    <td>send error to standard output</td>
	</tr>
	<tr>
	    <td>script > log.txt 2 > errlog.txt</td>
	    <td></td>
	</tr>
	<tr>
	    <td><br />
</td>
	    <td></td>
	</tr>
	<tr>
	    <td>uptime</td>
	    <td>show uptime since last reboot, and average load in the past 1, 5, 15 mins</td>
	</tr>
	<tr>
	  <td>/sbin/shutdown -h now</td>
	  <td>halt -p; init 0</td>
	  </tr>
	<tr>
	  <td>/sbin/shutdown -r now</td>
	  <td>reboot; init 6</td>
	  </tr>
	<tr>
	    <td>top</td>
	    <td>check CPU, mem swap processes</td>
	</tr>
	<tr>
	    <td>dmesg</td>
	    <td>check various hardware info</td>
	</tr>
	<tr>
	    <td>nohup command [argument]</td>
	    <td>runs a command even if the session is disconnected or the user logout.</td>
	</tr>
	<tr>
	    <td><br />
</td>
	    <td></td>
	</tr>
	<tr>
	    <td>adduser/useradd accountname</td>
	    <td>add new user</td>
	</tr>
	<tr>
	    <td>passwd accountname</td>
	    <td>change password for user</td>
	</tr>
	<tr>
	    <td>groupadd groupname</td>
	    <td>groupdel groupname</td>
	</tr>
	<tr>
	    <td>useradd -g groupname username</td>
	    <td></td>
	</tr>
	<tr>
	    <td>userdel johnrm<br />
        rm -rf /home/john</td>
	<td>these two combine = userdel -r john</td>
	</tr>
	
	<tr>
	  <td>su - <br />
	    su - user</td>
	  <td>switch to root account or other user, omit the hyphen without going to the respective home directory and source its environment files.</td>
	  </tr>
	<tr>
	    <td><br />
</td>
	    <td></td>
	</tr>
	<tr>
	    <td>/etc/hosts<br />
		/etc/sysconfig/network<br />
		service xinetd restart</td>
	<td>amend these two files in order to change hostname<br />
	  save the file and restart the xinetd service.</td>
	</tr>
	<tr>
	    <td>/etc/sysconfig/network-scripts/ifcfg-eth0</td>
	    <td></td>
	</tr>
	<tr>
	    <td>/etc/host.conf</td>
	    <td>specify order of hosts, bind</td>
	</tr>
	<tr>
	    <td>/etc/resolv.conf</td>
	    <td>nslookup look for this config file</td>
	</tr>
	<tr>
	    <td>/etc/named.conf/named start</td>
	    <td></td>
	</tr>
	<tr>
	    <td>/var/named/*</td>
	    <td></td>
	</tr>
	<tr>
	    <td>/var/log/messages</td>
	    <td></td>
	</tr>
	<tr>
	    <td><br /></td>
	    <td></td>
	</tr>
	<tr>
	  <td>ifconfig eth0 inet  192.168.0.1 broadcast 192.168.0.255 netmask&nbsp; 255.255.255.0 up<br />
service network restart</td>
	  <td>configure your  eth0 with a static ip through command line.</td>
	  </tr>
	<tr>
	  <td>system-config-network</td>
	  <td> GUI to  configure. Do not forget to restart the network after your configuration.</td>
	  </tr>
	<tr>
	    <td>dhcpcd wlan 0</td>
	    <td>start wireless network</td>
	</tr>
	<tr>
	    <td>dhcpcd -k wlan 0</td>
	    <td>stop wireless network</td>
	</tr>
	<tr>
	    <td>cardctl eject/insert</td>
	    <td></td>
	</tr>
	<tr>
	    <td>tracert www.yahoo.com</td>
	    <td>windows is traceroute</td>
	</tr>
	<tr>
	    <td>nmap hostname</td>
	    <td>check host opened port</td>
	</tr>
	<tr>
	    <td>netstat -nuatp</td>
	    <td>check localhost opened port</td>
	</tr>
	<tr>
	  <td>free<br />
	    free -m</td>
	  <td>check memory usage<br />
	    in MB</td>
	  </tr>
	<tr>
	  <td>/etc/rc.d/init.d/ipchains stop/start</td>
	  <td>start/stop firewall</td>
	  </tr>
	<tr>
	  <td>ifconfig</td>
	  <td>check network status, i.e. ip address; ipconfig in windows</td>
	  </tr>
	<tr>
	    <td>ipchains -L</td>
		<td></td>
	</tr>
	<tr>
	    <td>/etc/sysconfig/ipchains</td>
		<td></td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	  </tr>
	<tr>
	  <td>id; id username<br />
	    groups</td>
	  <td>print the group info of the user in</td>
	  </tr>
	<tr>
	  <td>groupadd -g 600 dba<br />
	    groupadd dba</td>
	  <td>add user group dba</td>
	  </tr>
	<tr>
	  <td>usermod -g oinstall oracle</td>
	  <td>change existing user oracle primary group to oinstall</td>
	  </tr>
	<tr>
	  <td>usermod -G oper -a oracle</td>
	  <td>append supplemental/secondary group for existing user </td>
	  </tr>
	<tr>
	  <td>cat /etc/group</td>
	  <td>check existing user groups</td>
	  </tr>
	<tr>
	  <td>chgrp groupname filename</td>
	  <td>change file or directory's owner group</td>
	  </tr>
	<tr>
	    <td>chown -R nobody:nobody dir</td>
		<td>change ownership and group of a directory or file</td>
	</tr>
	<tr>
	  <td>/etc/inittab<br />
	    init 5</td>
	  <td>config init level, i.e. /etc/rc.d/init.d /etc/rc.d/rc3.d /etc/rc.d/rc5.d<br />
	    switch to graphical mode, need to be root </td>
	  </tr>
	<tr>
	    <td><br />
</td>
		<td></td>
	</tr>
	<tr>
	    <td>rpm -qal | grep mozilla | more</td>
		<td>query for software package already installed and which directory is installed</td>
	</tr>
	<tr>
	    <td>rpm -qpi name.rpm</td>
		<td></td>
	</tr>
	<tr>
	    <td>rpm -qpl name.rpm</td>
		<td>list all files in pm</td>
	</tr>
	<tr>
	    <td>rpm -i name.rpm<br />
	      rpm -Uvh</td>
		<td>install rpm package, U means upgrade, will perform install if no upgrade available.</td>
	</tr>
	<tr>
	  <td>yum install/update/search packagename</td>
	  <td>&nbsp;</td>
	  </tr>
	<tr>
	  <td>yum list</td>
	  <td>list available packages in repository</td>
	  </tr>
	<tr>
	  <td>yum search keyword</td>
	  <td>search for packages</td>
	  </tr>
	<tr>
	  <td>yum check-update</td>
	  <td>check for updates</td>
	  </tr>
	<tr>
	  <td>yum update</td>
	  <td>update the whole system,may need to run vmware-config-tools.pl again and restart virtual machine</td>
	  </tr>
	<tr>
	  <td><br /></td>
	  <td>&nbsp;</td>
	  </tr>
	<tr>
	    <td>/etc/profile.d/*</td>
	    <td>put env files here to be sourced at startup</td>
	</tr>
	<tr>
	    <td>/usr/bin/isainfo -kv</td>
	    <td>check 32/64 bit sparc machine</td>
	</tr>
	<tr>
	    <td>/etc/mail/sendmail.mc</td>
	    <td></td>
	</tr>
	<tr>
	    <td>date</td>
	    <td>show system date and time</td>
	</tr>
	<tr>
	    <td>/etc/sysconfig/clock</td>
	    <td></td>
	</tr>
	<tr>
	    <td>/etc/ntp.conf</td>
	    <td>server ntp.nus.edu.sg</td>
	</tr>
	<tr>
	    <td>ntpupdate ntp.nus.edu.sg</td>
	    <td>network time protocol, set date and time via ntp server</td>
	</tr>
	<tr>
	    <td>ntpq -p</td>
	    <td>view synchronization status</td>
	</tr>
	<tr>
	    <td>service ntpd restart</td>
	    <td>ntp daemon restart</td>
	</tr>
	<tr>
	    <td>chkconfig --level 2345 ntpd on/off<br />
	      chkconfig --list bluetooth<br />
	      chkconfig --list</td>
	    <td>start/stop this daemon on level 2345<br />
	      list status of bluetooth daemon<br />
	      list all service status</td>
	</tr>
	<tr>
	    <td>setclock</td>
	    <td>set hardware clock (HC)</td>
	</tr>
	<tr>
	    <td>hwclock</td>
	    <td>read HC</td>
	</tr>
	<tr>
	    <td>hwclock --systohc --utc</td>
	    <td>set HC with UTC time based on OS time</td>
	</tr>
	<tr>
	    <td>hwclock --systohc</td>
	    <td>set HC with local time based on OS time</td>
	</tr>
	<tr>
	    <td>hwclock --set --date "22 Mar 2002 13:17"</td>
	    <td>set HC with the time specified in the string</td>
	</tr>
</tbody>
</table>

	<h4>SSL secure transfer</h4>
    <div class="codeblock">sftp user@host:dir/<br>
scp files_to_be_copied user@host:/dir/new_file_name<br>
pscp -r source_dir kevinm@host:/home/kevinm</div>
<h4>vi</h4>
    <div class="codeblock">edit .exrc at home dir<br>
:set showmode 		#turn on show mode<br>
:set nu 		#turn on show line number<br>
:set nonu 		#turn off show line number</div>
<h4>List directory content while cd into it, put it inside ~/.bashrc or /etc/bashrc for all users</h4>
	<pre class="codeblock">alias cd='cdx'
function cdx
{
	if 'cd' "$@"
	then
	echo $PWD  # omit this line if you have PS1 set \w for the prompt
	ls -aF
	fi 
}</pre>
    <p>Set bash terminal prompt, i.e. PS1 variable<br />
      <div class="codeblock">change the line 37 in /etc/bashrc from [ &quot;$PS1&quot; = &quot;\\s-\\v\\\$ &quot; ] &amp;&amp; PS1=&quot;[\u@\h \W]\\$ &quot;<br />
        to [ &quot;$PS1&quot; = &quot;\\s-\\v\\\$ &quot; ] &amp;&amp; PS1=&quot;[\u@\h \w]\\$ &quot;</div><br />
      i.e. only change W to w to display the full directory.
  
    <p>Set PATH variable for all users in /etc/profile (Functions and aliases go in /etc/bashrc), e.g. <br />
    <div class="codeblock">export MANPATH=&quot;/usr/man:/usr/X11R6/man&quot; </div>
      <p>Use csh or tcsh to submit a job as background, close the terminal, the job is still running. Other shell cannot. </p>
<p>apache common directories:<br />
  configuration file: /etc/httpd/conf/httpd.conf <br />
  root web folder: /var/www/html</p>
<p>setup passowrd for room in mysql:<br />
</p>
<div class="codeblock">mysql<br />
  mysql&gt; USE mysql;
  <br />
  mysql&gt; UPDATE user set password=password('newpassword') where user='root';<br />
  mysql&gt; flush privileges;
</div>
<p><a href="http://www.yolinux.com/TUTORIALS/LinuxTutorialNetworking.html" target="_blank">TCP/IP Network Configuration Files:</a></p>
DNS Server conf file: /etc/resolv.conf - host name resolver configuration file:<br />
  <div class="codeblock"><br />
  search name-of-domain.com  - Name of your domain or ISP's domain if using their name server<br />
  nameserver 192.168.80.2<br />
  nameserver 210.193.2.34<br />
  nameserver 210.193.2.36  </div>
  <br />
File: /etc/hosts - locally resolve node names to IP addresses<br />
<br />
<div class="codeblock">127.0.0.1         your-node-name.your-domain.com  localhost.localdomain  localhost <br />
  192.168.80.129  localhost.localdomain   localhost</div><br />

<p>Linux to first resolve a host name by looking at the       local hosts file(/etc/hosts), then if the name is not found look      to your DNS server as defined by /etc/resolv.conf and if not found there look to your NIS server. </p>
<p>Command line assign ip address:<br />
</p>
<div class="codeblock">/sbin/ifconfig eth0 192.168.10.12 netmask 255.255.255.0 broadcast 192.168.10.255</div></p>
<p><strong>/etc/sysconfig/network</strong> file contains basic information about the network in general<div class="codeblock">NETWORKING=yes<br />
  NETWORKING_IPV6=no<br />
  HOSTNAME=localhost<br />
  GATEWAY=&quot;XXX.XXX.XXX.YYY&quot; - Used if your network is connected to another network or the internet. Static IP configuration. Gateway not defined here for DHCP client. <br />
</div><br />
  <br />
  You can change hostname in the above file or use command, then restart network service:<br />
  <div class="codeblock">hostname new-host-name </div>
  <p>The configuration files&nbsp;  that initializes the network devices are located in the<strong>/etc/sysconfig/network-scripts</strong> directory, and can easily be edited to adjust the parameters for each device. A  general setup of the eth0 ( the first ethernet card) looks like the fillowing.  You need to open it in a text editor: </p>
<div class="codeblock">vi /etc/sysconfig/network-scripts/ifcfg-eth0# Internal Ethernet Device  (STATIC)<br />
  DEVICE=eth0<br />
  BOOTPROTO=static<br />
  HWADDR=00:0C:29:22:31:EA<br />
  ONBOOT=yes<br />
  TYPE=Ethernet<br />
  USERCTL=yes<br />
  IPV6INIT=no<br />
  PEERDNS=yes<br />
  IPADDR=192.168.80.129<br />
  NETMASK=255.255.255.0<br />
  # the following two are optional<br />
  BROADCAST=192.168.80.255<br />
  NETWORK=192.168.80.0</div><br />
  <br />
  For DHCP setting:<br />
  <div class="codeblock">  DEVICE=eth0<br />ONBOOT=yes<br />BOOTPROTO=dhcp<br>
  </div>
<p>Shell Programming: </p>
    <pre class="codeblock">if [ $HOSTNAME = "ganymede.cc.nus.edu.sg" ]
then
    ...
fi
</pre>
    <p><strong>apache virtualhost:</strong></p>
    <p>in windows: <a href="http://apptools.com/phptools/virtualhost.php">http://apptools.com/phptools/virtualhost.php</a><br />
      in Linux: <a href="http://httpd.apache.org/docs/2.0/vhosts/examples.html">http://httpd.apache.org/docs/2.0/vhosts/examples.html </a><br />
      In /etc/httpd/conf/httpd.conf
      <br />
      <pre class="codeblock"># Ensure that Apache listens on port 80<br />
Listen 80</p>
# Listen for virtual host requests on all IP addresses<br />
NameVirtualHost *:80
&lt;VirtualHost *:80&gt;
      DocumentRoot /home/kevin/php.projects
      ServerName vmware_centos
    # Other directives here
&lt;VirtualHost&gt;

&lt;VirtualHost *:80&gt;
      DocumentRoot /www/example2
      ServerName www.example2.org</p>
    # Other directives here
&lt;/VirtualHost&gt;</pre> 
    <p><strong>Don't forget</strong> to change the directory <span class="code_inline">/home/kevin</span> to be executable to others: <span class="code_inline">chmod -R +x /home/kevin</span><br />
    </p>
        </div>
    <!-- InstanceEndEditable --></div><!-- end of rightcolumn div -->
</div><!-- end of container div -->

<div id="footer">
	<p>Website design by <a href="../index.html">Kevin Mu Qing</a>; Hosting by <a href="http://www.jimlei.com" target="_blank">Jim Xianyu Lei</a></p>
</div>

</body>
<!-- InstanceEnd --></html>
